//
//  PersonalCenterViewController.m
//  时尚男士
//
//  Created by Jupiter on 15/6/3.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//
#import "AboutUsViewController.h"
#import "PersonalCenterViewController.h"
#import "MyCell.h"
#import "SearchViewController.h"
#import "collecTionCtroller.h"
#import "SetUpViewController.h"
#define Width self.view.frame.size.width
@interface PersonalCenterViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, retain) NSMutableArray *arr;
@property (nonatomic, retain) NSMutableArray *arr1;
@property (nonatomic, retain) NSUserDefaults *user;
@property (nonatomic, retain)UITableView *tab;
@property (nonatomic, retain) MyCell *cell;
@end

@implementation PersonalCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.jpg"]];
    self.navigationController.navigationBar.translucent = NO;
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, Width, Width / 1000 * 722)];
    [self.view addSubview:imageView];
    imageView.image = [UIImage imageNamed:@"1.jpg"];
    [imageView release];
    self.tab = [[UITableView alloc] initWithFrame:CGRectMake(0, Width / 1000 * 722, Width, 176) style:UITableViewStylePlain];
    self.tab.delegate = self;
    self.tab.dataSource = self;
    [self.view addSubview:self.tab];
    self.user = [NSUserDefaults standardUserDefaults];
    if (![self.user boolForKey:@"name"]) {
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg1.jpg"]];
    }
    self.arr = [NSMutableArray arrayWithObjects:@"我的收藏",@"设置",@"关于我们",@"搜索专题", nil];
    self.arr1 = [NSMutableArray arrayWithObjects:@"shoucang.png",@"set.png",@"center.png",@"sb.png" ,nil];

    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(receiveNoficiation:) name:@"name" object:nil];
     [_tab release];

    // Do any additional setup after loading the view.
}
- (void)receiveNoficiation:(NSNotification *)noti{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    if ([user boolForKey:@"name"]) {
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.jpg"]];
        NSLog(@"改变背景");
        self.cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg1.jpg"]];
        [self.tab reloadData];
    }else{
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg1.jpg"]];
        NSLog(@"改变背景");
        self.cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"xbg.png"]];
        [self.tab reloadData];
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   self.cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    if (self.cell == nil) {
        self.cell = [[MyCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"reuse"];
    }
    
    self.cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"xbg.png"]];
    if (![self.user boolForKey:@"name"]) {
        self.cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg1.jpg"]];
    }
    self.cell.lable.text = [self.arr objectAtIndex:indexPath.row];
    self.cell.imageView1.image = [UIImage imageNamed:[self.arr1 objectAtIndex:indexPath.row]];
    return self.cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        collecTionCtroller *collect = [[collecTionCtroller alloc] init];
        [self.navigationController pushViewController:collect animated:NO];
        [collect release];
    }if (indexPath.row == 1) {
        SetUpViewController *setUp = [[SetUpViewController alloc] init];
        [self.navigationController pushViewController:setUp animated:NO];
        [setUp release];
    }if (indexPath.row == 2) {
        AboutUsViewController *ab = [[AboutUsViewController alloc] init];
        [self.navigationController pushViewController:ab animated:NO];
        [ab release];
    }if (indexPath.row == 3) {
        SearchViewController *search = [[SearchViewController alloc] init];
        [self.navigationController pushViewController:search animated:NO];
        [search release];
        
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
